package com.day01;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Iterator;

/*
取数的逻辑叫：读取文件中的数据
 */
//mysql
public class MyIterator implements Iterator<Hero> {
    private BufferedReader bufferedReader = null;
    private String line = null;

    //在构造器里面打开文件，读取数据
    public MyIterator() throws Exception {
        bufferedReader = new BufferedReader(new FileReader("D:\\develop\\ideaWorkSpace\\myself\\doit40\\scala40\\src\\data\\Hero.txt"));
    }

    @Override
    public boolean hasNext() {
        boolean flag = true;
        try {
            line = bufferedReader.readLine();
            //代表我已经读完了
            if (line == null) {
                flag = false;
            } else {
                flag = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    @Override
    public Hero next() {
        //1,好似给_100::90
        String[] arr = line.split(",");
        String[] arr1 = arr[1].split("_");
        String[] arr2 = arr1[1].split("::");
        return new Hero(Integer.parseInt(arr[0]),arr1[0],Integer.parseInt(arr2[0]),Integer.parseInt(arr2[1]));
    }
}
